package com.jianganming.command;

/**
 * 命令设计模式
 */
public class CommandTest {
    public static void main(String[] args) {
        Controller controller = new Controller();
        controller.excuse(PlayEnum.play);

        controller.excuse(PlayEnum.pause);

        controller.excuse(PlayEnum.stop);
    }
}

//命令控制器
class Controller{
    public void excuse(PlayEnum playEnum){
        playEnum.getAction().excuse();
    }
}

//命令枚举
enum PlayEnum{
    play("play",new PlayAction()),
    pause("pause",new PauseAction()),
    stop("stop",new StopAction());

    private String name;
    private IAction action;

    public String getName() {
        return name;
    }

    public IAction getAction() {
        return action;
    }

    PlayEnum(String name, IAction action) {
        this.name=name;
        this.action=action;
    }
}

class Play{
    public void play(){
        System.out.println("正常播放");
    }
    public void pause(){
        System.out.println("暂停播放");
    }
    public void stop(){
        System.out.println("停止播放");
    }
}

interface IAction{
    void excuse();
}

class PlayAction implements IAction{
    Play play = new Play();
    @Override
    public void excuse() {
        play.play();
    }
}

class PauseAction implements IAction{
    Play play = new Play();
    @Override
    public void excuse() {
        play.pause();
    }
}

class StopAction implements IAction{
    Play play = new Play();
    @Override
    public void excuse() {
        play.stop();
    }
}




